package com.cy.pj.sys.controller;

import com.cy.pj.sys.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/menu/")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @RequestMapping("doFindObjects")
    public JsonResult doFindObjects() {
        return new JsonResult(sysMenuService.findObjects());
    }

    //删除接口
    @RequestMapping("doDeleteObject")
    public JsonResult doDeleteObject(Integer id) {
        sysMenuService.deleteObject(id);
        return new JsonResult("delete ok");
    }

    // 菜单添加接口
    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(SysMenu sysMenu) {
        sysMenuService.insertObject(sysMenu);
        return new JsonResult("save ok");
    }

    // 返回添加页面的上级菜单
    @RequestMapping("doFindZtreeMenuNodes")
    public JsonResult doFindZtreeMenuNodes() {
        return new JsonResult(
                sysMenuService.findZtreeMenuNodes());
    }

    // 更新菜单对象
    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(SysMenu sysMenu) {
        sysMenuService.insertObject(sysMenu);
        return new JsonResult("update ok");
    }
}
